﻿<cfscript>
/** 
* ORM CETEntry
* 
* @hint "Hibernate persistenter t_cet_entry. 外语等级考试报名情况表" 
* 
*/ 

component 
	displayname="public.service.orm.senate.CETEntry" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="CETEntry" 
	table="t_cet_entry"
	{

	property type="string" name="EntryID" column="eid" fieldtype="id" generator="assigned" hint="报名号";

	property type="string" name="Charged" column="is_charged" hint="是否缴费";
	property type="string" name="ApplyDate" column="apply_date" hint="报名时间";

	property type="string" name="EntryProp" column="entry_prop" hint="报名属性";

	property type="string" name="AdmissionNo" column="admission_id" hint="准考证号";
	property type="string" name="ExamRoom" column="exam_room" hint="考场";
	property type="string" name="ExamRoomIndex" column="exam_room_id" hint="考场序号";
	property type="string" name="SiteIndex" column="exam_room_idx" hint="座次";

	property name="Term" fieldtype="many-to-one" fkcolumn="term_id" cfc="Term" hint="学期";
	property name="CET" fieldtype="many-to-one" fkcolumn="exam_id" cfc="CET" hint="水平测试项目";
	property name="Student" fieldtype="many-to-one" fkcolumn="stu_id" cfc="Student" hint="学生";

	/**
	* @hint "自定义主键规则"
	* 
	* @TermID "学期代码"
	* @StudentID "学生"
	*/
	public string function getNextID( required string TermID, required string StudentID ) output=false {
		
		var nextID = arguments.TermID & "," & arguments.StudentID & "," & numberFormat(1, "0_");
		
		var checkArray = ORMExecuteQuery("select EntryID from CETEntry 
											where Term.TermID = :termId and Student.StudentID = :studentId
											order by EntryID desc", { termId=arguments.TermID, studentId=arguments.StudentID }, { maxResults=1 });
		
		/* 
			主键生成规则 VARCHAR(30)
			
			3位学期代码, 20位学号, 2位流水号
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.TermID & "," & arguments.StudentID & "," & numberFormat(right(checkArray[1], 2) + 1, "0_");
			
		}
		
		return nextID;

	}

		
}

</cfscript>